surface.CreateFont("Default", 40, 100, true, true, "Title")

function ShowClass()
	Inited = true

	gui.EnableScreenClicker(true)
	gui.SetMousePos(ScrW()/2, ScrH()/2)

	ClassMenu = true
	
	OpenTime = CurTime()
end	
function HideClass()
	if alpha == 0 then return end
	
	gui.EnableScreenClicker(false)

	ClassMenu = false
		
	HideTime = CurTime()
end	

OpenTime = CurTime()
HideTime = CurTime()

local function DrawBackground(x, y, w, h, color)
	local bx = x - w/2
	local by = y - h/2
	
	draw.RoundedBox(4, bx, by, w, h, color)
end

local function DrawOption(x, y, w, h, title, color)
	local bx = x - w/2
	local by = y - h/2
	
	draw.RoundedBox(4, bx, by, w, h, color)

	draw.SimpleText(title, "Title", x, y, Color(255, 255, 255, color.a), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
end

local tt = 0
local mt = 0
local bt = 0
local lh = 0

local th = true
function OnTopHover()
	local x = ScrW()/2
	local y = ScrH()/2
		
	local w = 500
	local h = 200
		
	local margin = 10
	
	if (gui.MouseY() < (y - (h/2 + margin))) and ClassMenu and th then
		tt = CurTime()
		lh = 1

		th = false
		mh = true
	end
end
hook.Add("HUDPaint", "OnTop", OnTopHover)

local mh = true
function OnMiddleHover()
	local x = ScrW()/2
	local y = ScrH()/2
		
	local w = 500
	local h = 200
	
	local margin = 10
	
	if (gui.MouseY() > (y - (h/2 + margin)) and gui.MouseY() < (y + (h/2 + margin))) and mh then
		mt = CurTime()
		
		mh = false
		th = true
		bh = true
	end
end
hook.Add("HUDPaint", "OnMiddle", OnMiddleHover)

local bh = true
function OnBottomHover()
	local x = ScrW()/2
	local y = ScrH()/2
		
	local w = 500
	local h = 200
		
	local margin = 10
	
	if (gui.MouseY() > (y + (h/2 + margin))) and ClassMenu and bh then
		bt = CurTime()
		lh = 2
		
		bh = false
		mh = true
	end
end
hook.Add("HUDPaint", "OnBottom", OnBottomHover)

local function Classes()
	local color = Color(0, 0, 0, alpha)

	if Inited then
		local hover = Color(0, 0, 0, 0)
	
		if ClassMenu then
			local t = 0.15
			local f = math.Clamp(CurTime() - OpenTime, 0, t)/t
			alpha = Lerp(math.EaseInOut(f, 0.4, 0.4), 0, 200)
			hover = Color(0, 0, 0, Lerp(math.EaseInOut(f, 0.4, 0.4), 0, 100))
		end
		if not ClassMenu then
			local t = 0.25
			local f = math.Clamp(CurTime() - HideTime, 0, t)/t
			alpha = Lerp(math.EaseInOut(f, 0.4, 0.4), 200, 0)
			hover = Color(0, 0, 0, Lerp(math.EaseInOut(f, 0.4, 0.4), 100, 0))
		end

		local client = LocalPlayer()
		
		local x = ScrW()/2
		local y = ScrH()/2
		
		local w = 500
		local h = 200
		
		local margin = 10
		
		top = gui.MouseY() < (y - (h/2 + margin)) and ClassMenu 
		middle = gui.MouseY() > (y - (h/2 + margin)) and gui.MouseY() < (y + (h/2 + margin)) and ClassMenu
		bottom = gui.MouseY() > (y + (h/2 + margin)) and ClassMenu
		
		if ClassMenu then
			local at = 0.25
			
			if top then
				local ht = tt
				local t = (CurTime() - ht)/at
				
				local alpha = Lerp(t, 0, 100)
				local leave = Lerp(t, 100, 0)
				
				middlehover = Color(0, 0, 0, leave)
				tophover = Color(0, 0, 0, alpha)
			elseif middle then
				local ht = mt
				local t = (CurTime() - ht)/at
				
				local alpha = Lerp(t, 0, 100)
				local leave = Lerp(t, 100, 0)
				
				if lh == 1 then
					tophover = Color(0, 0, 0, leave)
					bottomhover = Color(0, 0, 0, 0)
				elseif lh == 2 then
					tophover = Color(0, 0, 0, 0)
					bottomhover = Color(0, 0, 0, leave)
				else
					tophover = Color(0, 0, 0, 0)
					bottomhover = Color(0, 0, 0, 0)
				end
				middlehover = Color(0, 0, 0, alpha)
			elseif bottom then
				local ht = bt
				local t = (CurTime() - ht)/at
				
				local alpha = Lerp(t, 0, 100)
				local leave = Lerp(t, 100, 0)
				
				middlehover = Color(0, 0, 0, leave)
				bottomhover = Color(0, 0, 0, alpha)
			end
		end

		-- DrawBackground(x, y - (h + margin), w, h, tophover)
		DrawOption(x, y - (h + margin), w, h, "SUPPORT", color)
		
		-- DrawBackground(x, y, w, h, middlehover)
		DrawOption(x, y, w, h, "DEFAULT", color)
		
		-- DrawBackground(x, y + (h + margin), w, h, bottomhover)
		DrawOption(x, y + (h + margin), w, h, "EVADER", color)
	end
end
hook.Add("HUDPaint", "DrawClassMenu", Classes)

function CaptureMouseClicks(mouse)
	if not ClassMenu then return end

	if mouse == 107 then
		if top then
			RunConsoleCommand("class", "support")
		elseif middle then
			RunConsoleCommand("class", "default")
		elseif bottom then
			RunConsoleCommand("class", "evader")
		end
		HideClass()
		return true
	end
end
hook.Add("GUIMousePressed", "CaptureMouseClicks", CaptureMouseClicks)

concommand.Add("+class_menu", ShowClass)
concommand.Add("-class_menu", HideClass)
